#include "basic.h"
#include "sandcat.h"

//==============================================================================THREAD
void * thread( void *arg )
{	
	tty_set();
	set_fl(STDIN_FILENO, O_NONBLOCK);
//------------------------------------------------------------------------------WORKFLOW
	while(1)
	{
		char c = '\0';
		if( kbhit() ) c = getchar();

		switch( c ){

			case ' ': if( STATUS_flags("PLAYING") ) audio_pause();
					  else audio_playback( TRUE, 0, 0 );
					  break;
	
			case 'i': audio_playback( TRUE, 0, -1 ); break;

			case 'k': audio_playback( TRUE, 0, +1 ); break;

			case '\n': audio_stop(); break;

			case 'q': clr_fl(STDIN_FILENO, O_NONBLOCK);
					  tty_reset();
					  main_shutdown();
					  fprintf(stderr, "\n [ui]shell::EXIT \n");
					  pthread_exit(NULL);
					  break;
		
			case 'm':   if( STATUS_mute_on() ) audio_volume( TRUE, 0, FALSE );
						else audio_volume( TRUE, 0, TRUE );
						break;
			
			case ',': audio_volume( TRUE, -100, FALSE ); break;

			case '.': audio_volume( TRUE, +100, FALSE ); break;

			case ';': audio_seek( TRUE, -20 ); break;

			case '\'': audio_seek( TRUE, +20 ); break;
			
			default : 
						break;

		}
			
		//fprintf(stderr, " shell " );
		usleep(100000);
	}
//------------------------------------------------------------------------------

	clr_fl(STDIN_FILENO, O_NONBLOCK);
	tty_reset();

	
	return 0;
}